<div class="modal-header">
  <h5 class="modal-title mt-0" id="exampleModalLabel">{$sensor_name}</h5>
  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
    <span aria-hidden="true">&times;</span>
  </button>
</div>
<!--<form class="" method="post" action="{:U('sensor_param')}" target="ajaxifr"> -->
  <input type="hidden" name="id" value="{$datalist.id}" />
  <input type="hidden" name="sensor_code" value="{$sensor_code}" />
  <div class="modal-body">
    <fieldset>
      <div class="repeater-custom-show-hide">
        <div data-repeater-list="car">
          <table class="table table-centered  mb-0 ">
            <thead>
              <tr class="row">
                <th class="col-sm-2">参数名称</th>
                <th class="col-sm-4">范围</th>
                <th class="col-sm-2">默认值</th>
                <th class="col-sm-1">单位</th>
                <th class="col-sm-1">状态</th>
                <th class="col-sm-2">操作</th>
              <tr>
            </thead>
          </table>
          <empty name="datalist">
          <div data-repeater-item="">
            <table class="table table-centered mb-0">
              <tbody>
                <tr class="row">
                 <td style="display: none;"><input value="0" type="text" name="data[id][]" id="id" class="form-control set_id" /></td>
                  <td class="col-sm-2"><input value="" type="text" name="data[id][]" id="sensor_param_name" class="form-control" /></td>
                  <td class="col-sm-4"><input  value="" type="text" name="data[sensor_param_range][]" id="sensor_param_range" class="form-control" /></td>
                   <td class="col-sm-2"><input  value="" type="text" name="data[sensor_param_value][]" id="sensor_param_value" class="form-control" /></td>
                  <td class="col-sm-1"><input  value="" type="text" name="data[sensor_param_unit][]" id="sensor_param_unit" class="form-control" /></td>
                  <td class="col-sm-1">
                    <span class="p-2 state_text"  id="status"> 未更新</span>
                   </td>
                  <td class="col-sm-2">
                  <a   data-repeater-delete="" class="btn btn-danger btn-sm"  href="">删除</a>
                  <a    class="btn btn-danger btn-sm"   onclick="onsensor_update(this,'0')">修改</a>
                 
                  </td>
                <tr>
              </tbody>
            </table>
          </div>
          <else /> 
          <volist name="datalist" id="mlist">
          <div data-repeater-item="">
            <table class="table table-centered mb-0">
              <tbody>
                <tr class="row">
                 <td class="col-sm-2" style="display: none;"><input value="{$mlist.id}" type="text" name="data[id][]" id="id" class="form-control set_id" /></td>
                  <td class="col-sm-2"><input value="{$mlist.sensor_param_name}" type="text" name="data[sensor_param_name][]" id="sensor_param_name" class="form-control" /></td>
                  <td class="col-sm-4"><input  value="{$mlist.sensor_param_range}" type="text" name="data[sensor_param_range][]" id="sensor_param_range" class="form-control" /></td>
                    <td class="col-sm-2"><input  value="{$mlist.sensor_param_value}" type="text" name="data[sensor_param_value][]" id="sensor_param_value" class="form-control" /></td>
                  <td class="col-sm-1"><input  value="{$mlist.sensor_param_unit}" type="text" name="data[sensor_param_unit][]" id="sensor_param_unit" class="form-control" /></td>
                  <td class="col-sm-1" >
                    <span class="p-2 state_text" id="status">
                    <if condition="$mlist['id'] egt 1">已更新</if></span></td>
                  <td class="col-sm-2">
                  <a   data-repeater-delete="" class="btn btn-danger btn-sm"  href="">删除</a>
                  <a    class="btn btn-danger btn-sm"   onclick="onsensor_update(this,'{$mlist.id}')">修改</a>
                 
                  </td>
                <tr>
              </tbody>
            </table>
          </div>
          </volist>
          </empty> 


        </div>

        <div class="mt-2">
            <span data-repeater-create="" class="btn btn-light btn-md">
                <span class="fa fa-plus"></span>增加
            </span>
        </div>
      </div>

      <!--end fieldset-->

    </fieldset>
  </div>
<!--</form>-->


<script>
  $(document).ready(function () {
    'use strict';


    $('.repeater-custom-show-hide').repeater({
      show: function () {
        $(this).slideDown();
        console.log($(this).find('.set_id'))
        $(this).find('.set_id').val('0');
        $(this).find('#status').html('未更新');
      },
      hide: function (remove) {
        if (confirm('确认要删除？')) {
          $(this).slideUp(remove);
          onsensor_delete($(this).find('#id').val());
        }
      }
    });
  });
  
   function  onsensor_update(obj,id){
      var url = "{:U('sensor_param_update')}";
      
      var var_data = $(obj).parent().parent();
      var id = $(var_data).find("#id").val();
      var data = new Object();
       data.sensor_code = "{$sensor_code}";
       data.sensor_param_name= $(var_data).find("#sensor_param_name").val(); 
       data.sensor_param_value = $(var_data).find("#sensor_param_value").val(); 
       data.sensor_param_range_type = $(var_data).find("#sensor_param_range_type").val(); 
       data.sensor_param_range = $(var_data).find("#sensor_param_range").val(); 
       data.sensor_param_unit = $(var_data).find("#sensor_param_unit").val(); 
       
       data.id = $(var_data).find("#id").val();  
      
      $.post(url,{data:data},function(result){
        alert("更新成功");
        $('#editModal').modal('handleUpdate')
        
        
      });
      
  }
  
  function  onsensor_delete(id){
      var url = "{:U('sensor_param_delete')}";
      $.post(url,{id:id},function(result){
        alert("删除成功");
        $('#editModal').modal('handleUpdate')
        
        
      });
      
  }
</script>